# coding: utf-8
# Author: legend
# @Time： 2020/7/20 下午10:19

from tortoise import Tortoise, run_async

from apps.iacs.models import User
from settings import MYSQL_PASSWORD, MYSQL_HOST, MYSQL_USER, MYSQL_PORT, MYSQL_NAME


async def init():
    """
    Here we create a SQLit DB using file
    :return:
    """
    models = [
        'apps.iacs.models',
        'apps.log.models',
        'apps.resource.models',
        'apps.statistic.models',
    ]
    await Tortoise.init(db_url=f'mysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_NAME}',
                        modules={'models': models})
    await Tortoise.generate_schemas()


def get_all_user():
    user = User.all()
    print(user)


if __name__ == '__main__':
    run_async(init())
    get_all_user()
